import request from '@/utils/request'
import axios from 'axios'
import { remoteRequest } from '@/utils/remote.js'

const url = 'calculationTasks'

// 分页
export function getPage(params) {
  return request({
    url: `/${url}/getPage`,
    method: 'get',
    params
  })
}
// 新建
export function addTask(data) {
  return request({
    url: `/${url}/addTask`,
    method: 'post',
    data
  })
}
// 修改
export function upDateTasks(data, cancel) {
  return request({
    url: `/${url}/upDateTasks`,
    method: 'post',
    data,
    cancelToken: new axios.CancelToken(function executor(c) {
      cancel.c = c;
    })
  })
}
// 进度条
export function getProgress() {
  return request({
    url: `/${url}/getProgress`,
    method: 'get'
  })
}
// 详情
export function findById(params) {
  return request({
    url: `/${url}/findById`,
    method: 'get',
    params
  })
}
// 设为当前任务
export function settingTasks(id) {
  return request({
    url: `/${url}/settingTasks?id=${id}`,
    method: 'get'
  })
}
// 删除
export function deleteById(id) {
  return request({
    url: `/${url}/deleteById?id=${id}`,
    method: 'get'
  })
}

// 获取角色
export const getRole = () => {
  return remoteRequest('getRole', '', () => {
    return request({
      url: `/${url}/getRole`,
      method: 'get'
    })
  })
}

// 选择概率评估时触发获取年份
export function getYear(data) {
  return request({
    url: `/${url}/getYear`,
    method: 'post',
    data
  })
}